package pzl.com.canvasapi.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * @author zl.peng
 * @version [1.0, 2016-11-18]
 */
public class V_SaveLayer1 extends View {
    Paint mPaint = new Paint();
    private static final int LAYER_FLAGS = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG
            | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG
            | Canvas.CLIP_TO_LAYER_SAVE_FLAG;


    public V_SaveLayer1(Context context) {
        super(context);
    }

    public V_SaveLayer1(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public V_SaveLayer1(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawColor(Color.WHITE);
        mPaint.setColor(Color.RED);
        canvas.drawCircle(75, 75, 75, mPaint);
        canvas.saveLayerAlpha(0, 0, 200, 200, 150, LAYER_FLAGS);//一个新的图层而且是半透明的
        mPaint.setColor(Color.BLUE);
        canvas.drawCircle(125, 125, 75, mPaint);
        canvas.restore();
        mPaint.setColor(Color.YELLOW);
        canvas.drawCircle(125 + 37, 125 + 37, 37, mPaint);//可以看到它已经不透明了

    }
}
